package com.dhcc.bpm.common.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class ParameterRequestFilter implements Filter {
    private Logger log = LoggerFactory.getLogger(ParameterRequestFilter.class);

	@Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
        if(request.getParameterMap().size()<1){
//            String str = StreamUtils.copyToString(request.getInputStream(), Charset.forName("UTF-8"));
//            log.info("请求参数:{}", str);
            Map<String, String[]> map = new ConcurrentHashMap<>();
            ParameterRequestWrapper requestWrapper = new ParameterRequestWrapper((HttpServletRequest) request, map);
            chain.doFilter(requestWrapper, response);
            return;
        }
        chain.doFilter(request, response);
	}

	@Override
    public void destroy() {
		// TODO Auto-generated method stub
	}

	@Override
    public void init(FilterConfig paramFilterConfig) throws ServletException {
		// TODO Auto-generated method stub

	}

}